<template>
	<view style="padding-bottom: 120rpx;">
		<u-navbar :border-bottom='false' back-icon-size='48'>
			<view class="userBox" @click="navTo('../perCenter/perCenter')">
				<image :src="detail.head_pic" mode=""></image>
				<text>{{detail.nickname}}</text>
			</view>
			<view slot='right' class="leftBox">
				<view class="att">
					关注
				</view>
				<image style="width: 48rpx;height: 48rpx;" src="../../../static/imgs/fenxianghei.png" mode=""></image>
			</view>
		</u-navbar>
		<view class="swiper">
			<u-swiper :list="detail.images" width='100%' height="650" interval='3000' mode='rect' border-radius='0'>
			</u-swiper>
		</view>
		<view class="content">
			<view class="text">
				{{detail.content}}
			</view>
			<view class="more">
				<view class="tj">
					<image class="icon" src="../../../static/imgs/xgtj.png" mode=""></image>
					<text>相关推荐</text>
				</view>
				<view class="date">
					{{detail.show_time}}
				</view>
			</view>
			<view class="line">

			</view>
		</view>
		<view class="comment">
			<view class="num">
				共 {{commentCount}} 条评论
			</view>
			<view class="comment-ul">
				<view class="comment-li" v-for="(item,index) in commentList" :key='index'>
					<view class="hic">
						<image :src="item.head_pic" mode=""></image>
					</view>
					<view class="det">
						<view class="top">
							<view class="name">
								{{item.nickname}}
							</view>
							<view class="like">
								<u-icon name="heart" color="#666666" size="28"></u-icon>
							</view>
						</view>
						<view class="bot">
							<text class="text">
								{{item.content}}
							</text>
							<text class="time">{{item.create_time}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="commentBox">
			<view class="inputBox">
				<u-search placeholder="说点什么…" search-icon='edit-pen' :show-action='false' v-model="keyword"></u-search>
			</view>
		<view class="islike">
			<u-icon name="heart" color="#333333" size="32"></u-icon>
			<text>100</text>
		</view>
		<view class="collect">
			<u-icon name="star" color="#333333" size="32"></u-icon>
			<text>100</text>
		</view>
		<view class="pinlun">
			<u-icon name="chat" color="#333333" size="32"></u-icon>
			<text>100</text>
		</view>
		</view>
	</view>
</template>

<script>
	import myRequest from '@/api/index.js'
	import utils from '@/common/utils.js'
	export default {
		data() {
			return {
				id: '', // 帖子id
				detail: {},
				commentCount: 0,
				commentList: [],
				keyword:''
			}
		},
		onLoad(option) {
			this.id = option.id
			this.getArticle()
			this.getCommon()
		},
		methods: {
			navTo(url){
				uni.navigateTo({
					url:url
				})
			},
			// 获取评论
			async getCommon() {
				let res = await myRequest.getComment({
					forum_id: this.id,
					page: '1',
					num: '1000',
					category_type: '1',
				})
				if (res.status) {
					res.data.forEach(item=>{
						let time = utils.countDown(item.create_time,new Date())
						item.create_time = time[1]+'小时前'
					})
					this.commentCount = res.comment_count
					this.commentList = res.data
				}
			},
			// 匹配详情
			async getArticle() {
				let res = await myRequest.getComment({
					page: '1',
					num: '1000',
					category_type: '1',
				})
				if (res.status) {
					res.data.forEach(item => {
						if (item.id == this.id) {
							this.detail = item
						}
					})
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.userBox {
		display: flex;
		align-items: center;

		image {
			width: 72rpx;
			height: 72rpx;
			border-radius: 50%;
		}

		text {
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #333333;
			margin-left: 10rpx;
		}
	}

	.leftBox {
		display: flex;
		align-items: center;
		padding-right: 24rpx;

		.att {
			width: 108rpx;
			height: 48rpx;
			background: #FFFFFF;
			border: 1px solid #3587F7;
			border-radius: 40rpx;
			font-size: 24rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #3587F7;
			line-height: 48rpx;
			text-align: center;
			margin-right: 28rpx;
		}
	}

	.swiper {
		width: 100%;
	}

	.content {
		padding: 10rpx 20rpx;
		background-color: #FFFFFF;

		.text {
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 400;
			line-height: 44rpx;
			color: #333333;
			height: auto;
		}

		.more {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin: 20rpx 0;

			.tj {
				width: 178rpx;
				height: 52rpx;
				background: #E7F3FF;
				border-radius: 40rpx;
				display: flex;
				align-items: center;
				justify-content: center;

				.icon {
					width: 28rpx;
					height: 28rpx;
				}

				text {
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #3587F7;
					margin-left: 10rpx;
				}
			}

			.date {
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: rgba(153, 153, 153, 0.7);
			}
		}

		.line {
			width: 710rpx;
			height: 0px;
			border: 2rpx solid #F2F2F7;
		}
	}

	.comment {
		padding: 0 20rpx;
		background-color: #FFFFFF;

		.num {
			font-size: 24rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #333333;
		}

		.comment-ul {
			.comment-li {
				display: flex;
				padding-top: 20rpx;

				.hic {
					image {
						width: 68rpx;
						height: 68rpx;
						border-radius: 50%;
					}
				}

				.det {
					margin-left: 20rpx;
					border-bottom: 2rpx solid #F2F2F7;
					padding-bottom: 20rpx;

					.top {
						display: flex;
						align-items: center;

						.name {
							font-size: 28rpx;
							font-family: PingFang SC;
							font-weight: 400;
							color: #999999;
						}

						.like {
							margin-left: auto;
						}
					}

					.bot {
						.text {
							font-size: 28rpx;
							font-family: PingFang SC;
							font-weight: 400;
							color: #333333;
						}

						.time {
							font-size: 24rpx;
							font-family: PingFang SC;
							font-weight: 400;
							color: #999999;
							margin-left: 20rpx;
						}
					}
				}
			}
		}

	}

	.commentBox {
		width: 100%;
		height: 112rpx;
		background: #FFFFFF;
		border-top: 2rpx solid #F2F2F7;
		position: fixed;
		bottom: 0;
		display: flex;
		align-items: center;
		padding: 0 20rpx;

		.inputBox {
			width: 296rpx;
			height: 68rpx;
			background: #F2F2F7;
			border-radius: 40rpx;
		}

		.islike {
			margin-left: 78rpx;
		}

		.collect {
			margin-left: 48rpx;
		}

		.pinlun {
			margin-left: auto;

		}
	}
</style>
